package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.ArrayList;

import ngames.com.sushitv.R;
import ngames.com.sushitv.base.BaseListAdapter;
import ngames.com.sushitv.entity.ItemVideo;
import ngames.com.sushitv.entity.UpUser;

/**
 * Created by Jeffrey on 2016/7/27.
 */
public class SearchUserAdapter extends BaseListAdapter<UpUser> {

    public SearchUserAdapter(Context context, ArrayList<UpUser> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SearchUserViewHolder(mInflater.inflate(R.layout.item_upuser, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SearchUserViewHolder viewHolder = (SearchUserViewHolder) holder;
        viewHolder.setData(position);
    }

    class SearchUserViewHolder extends RecyclerView.ViewHolder {
        TextView nameText,contentText,uploadsText,followersText;
        ImageView coverImg;

        public SearchUserViewHolder(View itemView) {
            super(itemView);
            nameText= (TextView) itemView.findViewById(R.id.titleText);
            contentText= (TextView) itemView.findViewById(R.id.uploader);
            uploadsText= (TextView) itemView.findViewById(R.id.playCountText);
            followersText= (TextView) itemView.findViewById(R.id.readCountText);
            coverImg= (ImageView) itemView.findViewById(R.id.cover);
        }

        public void setData(int position) {
            UpUser upUser = getItem(position);
            nameText.setText(upUser.getName());
            contentText.setText(upUser.getSummary());
            uploadsText.setText(upUser.getUploads());
            followersText.setText(upUser.getFans());
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    /*.showStubImage(R.drawable.image_is_loading)            // 设置图片下载期间显示的图片
                    .showImageForEmptyUri(R.drawable.image_loading_failed)    // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.drawable.image_loading_failed)        // 设置图片加载或解码过程中发生错误显示的图片
                   */
                    .displayer(new RoundedBitmapDisplayer(190))
                    .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                    .cacheOnDisc(true)                            // 设置下载的图片是否缓存在SD卡中
                    .build();
            String workerImgStr = upUser.getAvatar();
            ImageLoader.getInstance().displayImage(workerImgStr, coverImg, options);
        }
    }
}
